package com.daykw.douyin;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

import com.daykw.douyin.task.StarAuthInfoThread;
import com.daykw.douyin.task.StarAuthSearchThread;
import com.daykw.douyin.utils.Const;

@SpringBootApplication
public class StartStarApp {
	private static Logger logger = Logger.getLogger(StartStarApp.class);

	public static void main(String[] args) {

		String node = null;
		if (args.length != 0 && args != null && StringUtils.isNotEmpty(args[0])) {
			node = args[0];
			Const.Node = node;
		}

		logger.info("当前节点node:" + node);
		SpringApplicationBuilder builder = new SpringApplicationBuilder(StartStarApp.class);

		builder.web(WebApplicationType.SERVLET).run();

		logger.info("##########spring boot 启动成功##########");

		try {

			PropertiesConfiguration props = new PropertiesConfiguration();
			props.setListDelimiter('#');

			InputStream stream = StartStarApp.class.getClassLoader().getResourceAsStream("application.properties");
			BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));

			props.load(br);

		} catch (Exception e) {
			e.printStackTrace();
		}
		ScheduledExecutorService scheduled21 = Executors.newSingleThreadScheduledExecutor();
		scheduled21.scheduleAtFixedRate(new StarAuthSearchThread(), 0, 1, TimeUnit.MINUTES);

		ScheduledExecutorService scheduled22 = Executors.newSingleThreadScheduledExecutor();
		scheduled22.scheduleAtFixedRate(new StarAuthInfoThread(), 0, 1, TimeUnit.MINUTES);

		logger.info("##########开始###########");

	}

}
